arcade-panel: start on hinge, better panel layout
[clinton/3d-models.git] / ble arcade controller / arcade-box.scad
index 21c55be..fe32dff 100644 (file)
@@ -5,9 +5,13 @@
 
 use <obiscad/bcube.scad>
 use <obiscad/attach.scad>
+use <joints.scad>
+
+
 
 // PREVIEW
-union () {
+preview();
+module preview () {
      rotate ([-10, 0, 0]) translate ([0, 0, box_h+20]) panel ();
      case ();
 }
@@ -26,10 +30,14 @@ base_h = 5; //fixme: thickness?
 cr = box_wall*2;
 cres = 0;
 
-$button_d = 28;
+$button_d = 30;
 js_width = 85;
 js_height = 40;
 
+hinge_joint_width = 4;
+hinge_joint_thickness = 5;
+hinge_base_height = 10;
+
 // PANEL COMPONENTS
 
 module button (bezel = $button_d+4) {
@@ -60,13 +68,41 @@ module case_base (h=base_h) {
 module case_walls () {
      difference() {
          bcube([panel_w, panel_h, box_h-base_h], cr, cres);
-         bcube([panel_w-box_wall, panel_h-box_wall, box_h], cr, cres);
+         bcube([panel_w-box_wall, panel_h-box_wall, box_h+1], cr, cres);
      }
+     %connector (case_connector_wall (x=10));
+     attach (case_connector_wall (x=10), hinge_connector_back ()) hinge_female ();
 }
 
 module case () {
      case_base ();
-     translate ([0, 0, (box_h)/2]) case_walls ();
+     translate ([0, 0, box_h/2]) case_walls ();
+}
+
+
+// todo:
+//   specify which wall (rear, front, left, right).
+//   offset from center of wall, as vector
+//   optional: inside/outside
+function case_connector_wall (x=0, y=0, z=0) = [ [panel_w/2-x, panel_h/2-y, (box_h-base_h)/2-z], [0,-1, 0], 0 ];
+
+// HINGE
+
+function hinge_connector_back (th=hinge_joint_thickness*2, h=hinge_base_height) = [ [0, th/2, h/2], [0,1, 0], 0 ];
+
+module hinge_female () {
+     w  = hinge_joint_width * 2;
+     th = hinge_joint_thickness * 2;
+     jt = hinge_joint_thickness;
+     jw = hinge_joint_width;
+     h  = hinge_base_height;
+
+     %connector (hinge_connector_back ());
+
+     difference () {
+         cube ([w, th, h], center=true);
+         joint_male_negative(male_joint_width=jw, male_joint_thickness=jt, forward_rom=90, backward_rom=90, male_joint_height=10);
+     }
 }
 
 
@@ -82,9 +118,9 @@ module panel () {
 module panel_attach (position, angle=0) {
      x = position[0];
      y = position[1];
-     c1 =  [ [x, y, base_h/2], [0,0,1], angle ]; //[0, 0, h];
+     c1 =  [ [x, y, base_h/2], [0,0,1], angle ];
      a1 = [ [0,0, 0], [0,0,0], 0 ];
-//     connector (c1);
+//    %connector (c1); // fixme: don't use 2d for layout
      attach (c1, a1) children ();
 }
 
@@ -94,20 +130,18 @@ module panel_layout () {
          panel_attach ([0, 0], 90) joystick ();
 
          // p1, coin (floating off in the distance...)
-         union () {
-              $button_d=18;
+         translate ([160, 0, 0]) {
+              $button_d=16;
               for (x = [0, $button_d+10]) {
-                   panel_attach ([x, 90]) button ();
-                   panel_attach ([x, 90]) button ();
+                   panel_attach ([x, 42]) button ();
               }
          }
 
          // a, b, c, d
-         union () {
-              buttons_offset = 60;
-              panel_attach ([buttons_offset, 0]) button ();
+         translate ([60, -20, 0]) {
+              panel_attach ([0, 0]) button ();
               for (i = [ 1 : 3 ]) {
-                   panel_attach ([i*($button_d+10)+buttons_offset-5, 30]) button ();
+                   panel_attach ([i*($button_d+10)-10, $button_d]) button ();
               }
          }
      }